import { Router } from "express";
import { authenticate } from "../middlewares/auth";
import { getCustomRoute } from "../controllers/customController";

const router = Router();

// Whitelist routes that bypass authentication
const whitelist = [
  "/login",
  "/public",
  "/api/posts",
  "/api/users",
  "/api/db1",
  "/api/db2",
  // "/api/main/users",
  // 暂时开放上传功能,后续进行身份验证,避免任意用户上传图片,暴露图片路径
  "/upload",
];

// Apply authentication middleware to non-whitelisted routes
router.use((req, res, next) => {
  console.log(req.path);
  if (whitelist.some((route) => req.path.startsWith(route))) {
    return next();
  }
  authenticate(req, res, next);
});

// Custom routes
router.get("/custom", getCustomRoute);

export default router;
